<template>
  <div>
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-form-item label="标题" prop="title">
        <el-input v-model="form.title" placeholder="请输入标题" />
      </el-form-item>
      <el-form-item label="内容">
        <editor v-model="form.content" :min-height="192"/>
      </el-form-item>
      <el-form-item label="排序" prop="sort">
        <el-input v-model="form.sort" placeholder="请输入排序" />
      </el-form-item>
      <el-form-item label="备注信息" prop="remark">
        <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm" style="margin-left: 550px">确 定</el-button>
      <el-button @click="cancel" style="margin-left: 20px">取 消</el-button>
    </div>
  </div>

</template>

<script>
import {getGuide, updateGuide} from "@/api/scp/guide";
export default {
  name: "edit",
  data(){
    return{
      form:{},
      rules:{
        title: [
          { required: true, message: '请输入标题', trigger: 'blur' }
        ],
        content: [
          { required: true, message: '请输入内容', trigger: 'blur' }
        ],
        sort: [
          { required: true, message: '请输入排序', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    var guideId = this.$route.query.guideId;
    this.init(guideId);
  },
  methods:{
    init(guideId){
      getGuide(guideId).then(response => {
          this.form = response.data;
      });
    },
    submitForm() {
      updateGuide(this.form).then(response => {
        this.$modal.msgSuccess("修改成功");
        this.$router.back();
      });
    },
    cancel() {
      this.$router.back();
    }
  },
}
</script>

<style scoped>

</style>
